<?php
/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2019/11/26
 * Time: 20:59
 */

namespace app\admin\controller;

use think\Session;
use think\Controller;
use app\admin\model\Login as LoginModel;

class Login extends Controller
{
    public function index()
    {
        return $this->fetch();
    }

    public function login($username, $password)
    {
        $user = LoginModel::get(['Aname' => $username]);
        if (empty($user)){
            $this->error('用户不存在');
        }
        if ($user['Apassword'] == $password) {
//            $_SESSION['username'] = $username;
            session('username', $username);
            $this->success('登录成功','emplist/index');
        } else {
            $this->error('登录失败');
        }
    }

    public function register()
    {
        return $this->fetch();
    }

    public function doreg()
    {
        var_dump($this->request->param());
        $result = $this->validate($this->request->param(),[
            'captcha|验证码'=>'require|captcha'
        ]);
        if (true !== $result) {
            var_dump($result);
        }
    }

    public function logout()
    {
        Session::clear();
        $this->success('推出与成功','login/index');
    }
}
